﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace Common
{
	public class ConfigSetting
	{
		private static ConfigSetting _instance = null;
		private StringDictionary Config = null;
		private static readonly object _lock = new object();
		private ConfigSetting()
		{
			Config = new StringDictionary();
			LoadConfig();
		}
		public static ConfigSetting Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (_lock)
					{
						if (_instance == null)
							_instance = new ConfigSetting();
					}
				}
				return _instance;
			}
		}


		public static void Refersh()
		{
			_instance = null;
		}

		private void LoadConfig()
		{
			
			NameValueCollection nc = System.Web.Configuration.WebConfigurationManager.AppSettings;
			foreach (var key in nc.AllKeys)
			{
				Config.Add(key.Trim().ToLower(), nc[key].Trim());
			}
		}
		public string this[string key]
		{
			get
			{
				key = key.ToLower();
				if(Config.ContainsKey(key))
					return Config[key];
				return string.Empty;
			}
		}


		public bool ISGM(string id)
		{
			string[] s = this["GMID"].Split(',');
			return s.Contains(id);
		}
	}
}
